package com.example.sinaweibo2.ui;

import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.example.sinaweibo2.R;
import com.example.sinaweibo2.bean.Task;
import com.example.sinaweibo2.logic.MainService;

public class LoginActivity extends Activity implements IWeiboActivity {

	private Button loginButton;
	private TextView loginTextView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		loginButton = (Button) findViewById(R.id.login_button); 
		loginTextView = (TextView) findViewById(R.id.login_text);
		
		loginButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {

				MainService.newTask(new Task(Task.WEIBO_LOGIN, null));
			}
		});
		startService(new Intent(this, MainService.class));
		MainService.addActivity(LoginActivity.this);
		
		Log.i("laf", "onCreate");
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Log.i("laf", "onStart");
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		
		Log.i("laf", "onRestart");
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Log.i("laf", "onResume");
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Log.i("laf", "onPause");
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Log.i("laf", "onStop");
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Log.i("laf", "onDestroy");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.login, menu);
		return true;
	}

	@Override
	public void init() {
		
	}

	@Override
	public void refresh(Object... params) {
		
		loginTextView.setText((String)params[0]);
//		loginTextView.setText(params[0].toString());
	}

}
